﻿using System; 
using System.Collections.Generic; 
using System.ComponentModel; 

namespace DataAccess{
[Serializable]
[GenWiseAttribute(IsDataSourceEntity = true) ]
public class user : INotifyPropertyChanged
 {


#region --- Class Fields / Objects  ---

[NonSerialized]
protected PropertyChangedEventHandler _propertyChanged;
private System.Int32 _id;
private System.String _login;
private System.String _pass;
private System.DateTime? _created;
private System.String _name;
private System.String _surname;
private System.String _email;
private System.String _gg;
private System.String _skype;
private System.String _avatar_mime;
private IList<answer> _answers;
private IList<art> _arts;
private IList<art_rate_type> _art_rate_types;
private IList<comment> _comments;
private IList<forum> _forums;
private IList<forum_to_User> _forum_to_Users;
private IList<friend> _friends;
private IList<friend> _friends1;
private IList<gallery> _galleries;
private IList<message> _messages;
private IList<message> _messages1;
private IList<visit> _visits;

#endregion


#region --- Class Properties ---

public virtual System.Int32 id 
{
get
{
return _id;
}
}

public virtual System.String login 
{
get
{
return _login;
}
set 
{
if ( _login != value) 
{
_login = value ;
OnPropertyChanged("login");
}
}
}

public virtual System.String pass 
{
get
{
return _pass;
}
set 
{
if ( _pass != value) 
{
_pass = value ;
OnPropertyChanged("pass");
}
}
}

/// <summary>
/// This property contains a calculated, bindable value of the DATE part of a DateTime property. If you want to only work with the DATE and ignore the underlying TIME component then you could use this property.
/// </summary>
/// <remarks>
/// Auto-Generated Property
/// </remarks>
public virtual System.String created_Date 
{
get
{
if (  !created.HasValue ) 
{ 
 return String.Empty;
} 
else 
{ 
if ( created.Value.ToShortDateString() == System.DateTime.MinValue.ToShortDateString() ) 
 return String.Empty;
else  
 return created.Value.ToShortDateString();
} 

}
set 
{
if ( string.IsNullOrEmpty( value ) )  
{
 if (string.IsNullOrEmpty(created_Time)) {

created = null;
}
 else
{
 created = Convert.ToDateTime( " " + System.DateTime.MinValue.ToShortDateString() + " " + created.Value.ToString("HH:mm:ss.fff") ) ;
}
}
 else
{
 if (string.IsNullOrEmpty(created_Time)) 
{
 created = Convert.ToDateTime( " " + value + " " + System.DateTime.MinValue.ToLongTimeString() ) ;
}
 else
{
 created = Convert.ToDateTime( " " + value + " " + created.Value.ToString("HH:mm:ss.fff") ) ;
}
}

}
}

/// <summary>
/// This property contains a calculated, bindable value of the TIME part of a DateTime property. If you want to only work with the TIME and ignore the underlying DATE component then you could use this property.
/// </summary>
/// <remarks>
/// Auto-Generated Property
/// </remarks>
public virtual System.String created_Time 
{
get
{
if (  !created.HasValue ) 
{ 
 return String.Empty;
} 
else 
{ 
if ( created.Value.ToShortTimeString() == System.DateTime.MinValue.ToShortTimeString() ) 
 return String.Empty;
else  
 return created.Value.ToShortTimeString();
} 

}
set 
{
if ( string.IsNullOrEmpty( value ) )  
{
 if (string.IsNullOrEmpty(created_Date)) 
{
created = null;
}
 else
{
 created = Convert.ToDateTime( " " + created.Value.ToShortDateString() + " " + System.DateTime.MinValue.ToLongTimeString() ) ;
}
}
 else
{
 if (string.IsNullOrEmpty(created_Date)) 
{
 created = Convert.ToDateTime( " " + System.DateTime.MinValue.ToShortDateString() + " " + value ) ;
}
 else
{
 created = Convert.ToDateTime( " " + created_Date + " " + value ) ;
}
}

}
}

public virtual System.DateTime? created 
{
get
{
return _created;
}
set 
{
if ( _created != value) 
{
_created = value ;
OnPropertyChanged("created");
}
}
}

public virtual System.String name 
{
get
{
return _name;
}
set 
{
if ( _name != value) 
{
_name = value ;
OnPropertyChanged("name");
}
}
}

public virtual System.String surname 
{
get
{
return _surname;
}
set 
{
if ( _surname != value) 
{
_surname = value ;
OnPropertyChanged("surname");
}
}
}

public virtual System.String email 
{
get
{
return _email;
}
set 
{
if ( _email != value) 
{
_email = value ;
OnPropertyChanged("email");
}
}
}

public virtual System.String gg 
{
get
{
return _gg;
}
set 
{
if ( _gg != value) 
{
_gg = value ;
OnPropertyChanged("gg");
}
}
}

public virtual System.String skype 
{
get
{
return _skype;
}
set 
{
if ( _skype != value) 
{
_skype = value ;
OnPropertyChanged("skype");
}
}
}

public virtual System.String avatar_mime 
{
get
{
return _avatar_mime;
}
set 
{
if ( _avatar_mime != value) 
{
_avatar_mime = value ;
OnPropertyChanged("avatar_mime");
}
}
}

/// <summary>
/// Collection of answer.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "952cc762-c03f-401d-a4e1-1820d9ab0ce6" , CollectionOfType = typeof(answer)) ]
public virtual IList<answer> answers 
{
get
{
 if (_answers == null) _answers = new List<answer>();

return _answers;
}
set 
{
if ( _answers != value) 
{
_answers = value ;
}
}
}

/// <summary>
/// Collection of art.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "da291ced-902c-41ba-ac86-9c9ef3b2108a" , CollectionOfType = typeof(art)) ]
public virtual IList<art> arts 
{
get
{
 if (_arts == null) _arts = new List<art>();

return _arts;
}
set 
{
if ( _arts != value) 
{
_arts = value ;
}
}
}

/// <summary>
/// Collection of art_rate_type.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "19b7cb74-63b7-4b0d-86d9-777c9652f016" , CollectionOfType = typeof(art_rate_type)) ]
public virtual IList<art_rate_type> art_rate_types 
{
get
{
 if (_art_rate_types == null) _art_rate_types = new List<art_rate_type>();

return _art_rate_types;
}
set 
{
if ( _art_rate_types != value) 
{
_art_rate_types = value ;
}
}
}

/// <summary>
/// Collection of comment.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "61b7e623-69b4-4eb0-b0e3-6df16cc1a69f" , CollectionOfType = typeof(comment)) ]
public virtual IList<comment> comments 
{
get
{
 if (_comments == null) _comments = new List<comment>();

return _comments;
}
set 
{
if ( _comments != value) 
{
_comments = value ;
}
}
}

/// <summary>
/// Collection of forum.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "1f5341be-96c9-4c0c-9e03-db96e6267eab" , CollectionOfType = typeof(forum)) ]
public virtual IList<forum> forums 
{
get
{
 if (_forums == null) _forums = new List<forum>();

return _forums;
}
set 
{
if ( _forums != value) 
{
_forums = value ;
}
}
}

/// <summary>
/// Collection of forum_to_User.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "54ae6b5b-7a32-41ae-8543-d371ffa242e2" , CollectionOfType = typeof(forum_to_User)) ]
public virtual IList<forum_to_User> forum_to_Users 
{
get
{
 if (_forum_to_Users == null) _forum_to_Users = new List<forum_to_User>();

return _forum_to_Users;
}
set 
{
if ( _forum_to_Users != value) 
{
_forum_to_Users = value ;
}
}
}

/// <summary>
/// Collection of friend.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "5dfc23d9-aa81-4877-a0f8-ef1c22d7b946" , CollectionOfType = typeof(friend)) ]
public virtual IList<friend> friends 
{
get
{
 if (_friends == null) _friends = new List<friend>();

return _friends;
}
set 
{
if ( _friends != value) 
{
_friends = value ;
}
}
}

/// <summary>
/// Collection of friend.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "a329f9c9-1664-466d-920e-e3dfbd4953fd" , CollectionOfType = typeof(friend)) ]
public virtual IList<friend> friends1 
{
get
{
 if (_friends1 == null) _friends1 = new List<friend>();

return _friends1;
}
set 
{
if ( _friends1 != value) 
{
_friends1 = value ;
}
}
}

/// <summary>
/// Collection of gallery.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "02762f2a-f68e-4dc3-ab7d-c2959548b9a4" , CollectionOfType = typeof(gallery)) ]
public virtual IList<gallery> galleries 
{
get
{
 if (_galleries == null) _galleries = new List<gallery>();

return _galleries;
}
set 
{
if ( _galleries != value) 
{
_galleries = value ;
}
}
}

/// <summary>
/// Collection of message.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "63b39533-2e88-47a2-b065-7a7a6e7b1f65" , CollectionOfType = typeof(message)) ]
public virtual IList<message> messages 
{
get
{
 if (_messages == null) _messages = new List<message>();

return _messages;
}
set 
{
if ( _messages != value) 
{
_messages = value ;
}
}
}

/// <summary>
/// Collection of message.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "3267caa1-3104-4dc1-8961-13f57d91073a" , CollectionOfType = typeof(message)) ]
public virtual IList<message> messages1 
{
get
{
 if (_messages1 == null) _messages1 = new List<message>();

return _messages1;
}
set 
{
if ( _messages1 != value) 
{
_messages1 = value ;
}
}
}

/// <summary>
/// Collection of visit.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "07998ded-95d0-4be0-93dc-46b1ed65b62b" , CollectionOfType = typeof(visit)) ]
public virtual IList<visit> visits 
{
get
{
 if (_visits == null) _visits = new List<visit>();

return _visits;
}
set 
{
if ( _visits != value) 
{
_visits = value ;
}
}
}

/// <summary>
/// Is this object Valid? 
/// </summary>
/// <remarks>
/// This is achieved by counting how many errors are returned from the Validate() method. If no errors are found then it's valid.
/// </remarks>
[Bindable(false)]
public virtual System.Boolean IsValid 
{
get
{
List<Error> _errors = this.Validate(); if ( _errors.Count > 0 ) return false; else return true;
}
}


#endregion


#region --- Class Methods --- 

/// <summary>
/// Raises PropertyChanged event.
/// </summary>
protected virtual void OnPropertyChanged(System.String ppropertyChanged)
{
if (_propertyChanged != null) _propertyChanged( this , new PropertyChangedEventArgs(ppropertyChanged));

}

/// <summary>
/// Create a new user object. 
/// </summary>
public  user()
{
_id = System.Int32.MinValue;

}

/// <summary>
/// Add a new art object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="part">An art object to be added to this objects collection.</param>
public virtual void Addart(art part)
{
if( part == null  ) throw new ArgumentNullException("part");
// Set the Parent Property
part.user = this;
if (!part.IsValid) { throw new Exception("part failed on the Validate() method." + Error.ErrorsToString( part.Validate() ) ); }
arts.Add(part);
}

/// <summary>
/// Delete an existing art object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="part">The art object to be removed from this objects collection.</param>
public virtual void Deletearts(art part)
{
if( part == null  ) throw new ArgumentNullException("part");
arts.Remove(part);
// Remove the Association with the Parent object
part.user = null;
}

/// <summary>
/// Add a new art_rate_type object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="part_rate_type">An art_rate_type object to be added to this objects collection.</param>
public virtual void Addart_rate_type(art_rate_type part_rate_type)
{
if( part_rate_type == null  ) throw new ArgumentNullException("part_rate_type");
// Set the Parent Property
part_rate_type.user = this;
if (!part_rate_type.IsValid) { throw new Exception("part_rate_type failed on the Validate() method." + Error.ErrorsToString( part_rate_type.Validate() ) ); }
art_rate_types.Add(part_rate_type);
}

/// <summary>
/// Delete an existing art_rate_type object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="part_rate_type">The art_rate_type object to be removed from this objects collection.</param>
public virtual void Deleteart_rate_types(art_rate_type part_rate_type)
{
if( part_rate_type == null  ) throw new ArgumentNullException("part_rate_type");
art_rate_types.Remove(part_rate_type);
// Remove the Association with the Parent object
part_rate_type.user = null;
}

/// <summary>
/// Add a new comment object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pcomment">An comment object to be added to this objects collection.</param>
public virtual void Addcomment(comment pcomment)
{
if( pcomment == null  ) throw new ArgumentNullException("pcomment");
// Set the Parent Property
pcomment.user = this;
if (!pcomment.IsValid) { throw new Exception("pcomment failed on the Validate() method." + Error.ErrorsToString( pcomment.Validate() ) ); }
comments.Add(pcomment);
}

/// <summary>
/// Delete an existing comment object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pcomment">The comment object to be removed from this objects collection.</param>
public virtual void Deletecomments(comment pcomment)
{
if( pcomment == null  ) throw new ArgumentNullException("pcomment");
comments.Remove(pcomment);
// Remove the Association with the Parent object
pcomment.user = null;
}

/// <summary>
/// Add a new forum object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pforum">An forum object to be added to this objects collection.</param>
public virtual void Addforum(forum pforum)
{
if( pforum == null  ) throw new ArgumentNullException("pforum");
// Set the Parent Property
pforum.user = this;
if (!pforum.IsValid) { throw new Exception("pforum failed on the Validate() method." + Error.ErrorsToString( pforum.Validate() ) ); }
forums.Add(pforum);
}

/// <summary>
/// Delete an existing forum object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pforum">The forum object to be removed from this objects collection.</param>
public virtual void Deleteforums(forum pforum)
{
if( pforum == null  ) throw new ArgumentNullException("pforum");
forums.Remove(pforum);
// Remove the Association with the Parent object
pforum.user = null;
}

/// <summary>
/// Add a new forum_to_User object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pforum_to_User">An forum_to_User object to be added to this objects collection.</param>
public virtual void Addforum_to_User(forum_to_User pforum_to_User)
{
if( pforum_to_User == null  ) throw new ArgumentNullException("pforum_to_User");
// Set the Parent Property
pforum_to_User.user = this;
if (!pforum_to_User.IsValid) { throw new Exception("pforum_to_User failed on the Validate() method." + Error.ErrorsToString( pforum_to_User.Validate() ) ); }
forum_to_Users.Add(pforum_to_User);
}

/// <summary>
/// Delete an existing forum_to_User object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pforum_to_User">The forum_to_User object to be removed from this objects collection.</param>
public virtual void Deleteforum_to_Users(forum_to_User pforum_to_User)
{
if( pforum_to_User == null  ) throw new ArgumentNullException("pforum_to_User");
forum_to_Users.Remove(pforum_to_User);
// Remove the Association with the Parent object
pforum_to_User.user = null;
}

/// <summary>
/// Add a new gallery object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pgallery">An gallery object to be added to this objects collection.</param>
public virtual void Addgallery(gallery pgallery)
{
if( pgallery == null  ) throw new ArgumentNullException("pgallery");
// Set the Parent Property
pgallery.user = this;
if (!pgallery.IsValid) { throw new Exception("pgallery failed on the Validate() method." + Error.ErrorsToString( pgallery.Validate() ) ); }
galleries.Add(pgallery);
}

/// <summary>
/// Delete an existing gallery object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pgallery">The gallery object to be removed from this objects collection.</param>
public virtual void Deletegalleries(gallery pgallery)
{
if( pgallery == null  ) throw new ArgumentNullException("pgallery");
galleries.Remove(pgallery);
// Remove the Association with the Parent object
pgallery.user = null;
}

/// <summary>
/// Add a new message object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pmessage">An message object to be added to this objects collection.</param>
public virtual void Addmessage(message pmessage)
{
if( pmessage == null  ) throw new ArgumentNullException("pmessage");
// Set the Parent Property
pmessage.user = this;
if (!pmessage.IsValid) { throw new Exception("pmessage failed on the Validate() method." + Error.ErrorsToString( pmessage.Validate() ) ); }
messages.Add(pmessage);
}

/// <summary>
/// Delete an existing message object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pmessage">The message object to be removed from this objects collection.</param>
public virtual void Deletemessages(message pmessage)
{
if( pmessage == null  ) throw new ArgumentNullException("pmessage");
messages.Remove(pmessage);
// Remove the Association with the Parent object
pmessage.user = null;
}

/// <summary>
/// Add a new message object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pmessage">An message object to be added to this objects collection.</param>
public virtual void Addmessages1(message pmessage)
{
if( pmessage == null  ) throw new ArgumentNullException("pmessage");
// Set the Parent Property
pmessage.user1 = this;
if (!pmessage.IsValid) { throw new Exception("pmessage failed on the Validate() method." + Error.ErrorsToString( pmessage.Validate() ) ); }
messages1.Add(pmessage);
}

/// <summary>
/// Delete an existing message object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pmessage">The message object to be removed from this objects collection.</param>
public virtual void Deletemessages1(message pmessage)
{
if( pmessage == null  ) throw new ArgumentNullException("pmessage");
messages1.Remove(pmessage);
// Remove the Association with the Parent object
pmessage.user1 = null;
}

/// <summary>
/// Add a new visit object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pvisit">An visit object to be added to this objects collection.</param>
public virtual void Addvisit(visit pvisit)
{
if( pvisit == null  ) throw new ArgumentNullException("pvisit");
// Set the Parent Property
pvisit.user = this;
if (!pvisit.IsValid) { throw new Exception("pvisit failed on the Validate() method." + Error.ErrorsToString( pvisit.Validate() ) ); }
visits.Add(pvisit);
}

/// <summary>
/// Delete an existing visit object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pvisit">The visit object to be removed from this objects collection.</param>
public virtual void Deletevisits(visit pvisit)
{
if( pvisit == null  ) throw new ArgumentNullException("pvisit");
visits.Remove(pvisit);
// Remove the Association with the Parent object
pvisit.user = null;
}

/// <summary>
/// Validates the object returning a list of errors if the validation fails.
/// </summary>
/// <remarks>
/// You can use the provided User CodeBlocks to add your own validations.
/// </remarks>
///<returns>Returns the List of Errors found during the Validation. If no errors are found null is returned.<returns>
public virtual List<Error> Validate()
{
List<Error> _errors = new List<Error>();
Error _error;
// Call Validator IsRequired for Column : login(Type:Required Field Validator)
_error = this.ValidateloginIsRequired() ;
 if ( _error != null ) { _errors.Add(_error); }
return _errors;
}

/// <summary>
/// Validation Method
/// </summary>
/// <remarks>
/// This method was automatically generated based on the DataBase Repository Validations for the Column : login
/// </remarks>
public virtual Error ValidateloginIsRequired()
{
if ( String.IsNullOrEmpty(login) ) 
{
 Error _error = new Error();
 _error.ErrorMessage = "login is required and therefore must have a value." ;
 return _error;
}
 return null;
}


#endregion


#region --- Class Events  ---

public event PropertyChangedEventHandler PropertyChanged 
{
   add {
_propertyChanged+= value;
   }
   remove {
_propertyChanged-= value;
   }
}


#endregion
}
}

